package com.yanqu.road.server.cmd.cookboy.process3;

import com.yanqu.road.entity.activity.cookboy.process3.CookBoy3BanquetReward;
import com.yanqu.road.pb.cookboy.CookBoyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.cookboy.CrossCookBoyMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.C_CROSS_COOK_BOY3_BANQUET_REWARD, desc = "小当家第3阶段获取奖励信息")
public class CrossBanquetRewardCmd extends CrossCommand {

    private long userId;
    private int activityId;
    private int banquetId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CookBoyProto.CookBoy3BanquetRewardReqMsg reqMsg = CookBoyProto.CookBoy3BanquetRewardReqMsg.parseFrom(packet.getBytes());
        userId = packet.getPlayerId();
        activityId = reqMsg.getActivityId();
        banquetId = reqMsg.getBanquetId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CookBoy3BanquetReward cookBoyBanquetReward = CrossCookBoyMgr.getBanquetReward(activityId,userId,banquetId);

        CookBoyProto.CookBoy3BanquetRewardRespMsg.Builder respMsg = CookBoyProto.CookBoy3BanquetRewardRespMsg.newBuilder();
        respMsg.setRet(cookBoyBanquetReward.getRet());
        if(cookBoyBanquetReward.getRet() == 0){
            respMsg.setBanquetId(banquetId);
            respMsg.setUserCount(cookBoyBanquetReward.getUserCount());
            respMsg.setIntegral(cookBoyBanquetReward.getIntegral());
            respMsg.setItemId(cookBoyBanquetReward.getOpenItemId());
        }
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.U_COOK_BOY3_BANQUET_REWARDR_REQ, respMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }

}
